#ifndef SRC_GAME_H
#define SRC_GAME_H

#include "../gfx/gfx.h"
#include "../sfx/sfx.h"
#include "../io/io.h"

#define MAX_ENTITIES 32
#define MAX_PLAYERS 2

void game_init(void);
void game_exit(void);

typedef struct
{
    int inUse;
    int entityIndex;

    float x, y;
    float dx, dy;
    float radius;

    float animTime;
    int baseAnim;

    int entityType;
    int health;
    //int nbKeys;
    int deleteFlag;

    int player;

    GFX_Sprite sprite;

} Game_Entity;

typedef struct
{
    int playerIndex;
    char name[32];
    char humanAddress[32];
    void *connection;

    int entityIndex;
    int camX, camY;
    int actions;
    int inUse;

    int nbKeys;
    int winStatus;
    int inPause;
    int itemPause;
    int superIndex;
    int superLevel;
    int superCharge;
    int superMaxCharge;
    float superChargeRechargeThink;

} Game_Player;

typedef struct
{
    char name[32];
    char humanAddress[32];
    void *connection;
    int isClient;

    int (*logic)(void *game, float dT);
    void (*collide_entity)(void *game, float ticks, Game_Entity *e1, Game_Entity *e2);
    void (*collide_tilemap)(void *game, float ticks, Game_Entity *e, int xtile, int ytile);
    void (*draw_player_gui)(void *game, int w, int h, int localPlayer);

    int currentPlayerIndex;
    float lastTime;
    Clock *time;
    Game_Player *players;
    int *localPlayers;
    Game_Entity *entities;
    GFX_Tilemap *tilemap;

    int gameOver;
    float gameOverTimeout;

} Game;

void game_draw(Game *game);
void game_delete(Game *game);

#endif
